package com.dawan.sbjy.controller;

import com.dawan.sbjy.Config.DynamicSwitchDataSource;
import com.dawan.sbjy.dao.UserDao;
import com.dawan.sbjy.service.impl.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
public class UserApi {

    @Resource
    UserService userService;

    @GetMapping("/admin/1")
    public String getMessage(){
        return "你已通过验证";
    }


    @PostMapping("/registe")
    public String registe(@RequestParam(value = "username",required = true) String username,@RequestParam("password") String password){
        String token;
//        token=GetToken.createToken(username);
        return "1";
    }

    @GetMapping("/testError")
    public String throwerror(){
        throw new RuntimeException("测试错误！");
    }

    @PostMapping("/test/dao")
    @DynamicSwitchDataSource(dataSource="mastersource")
    public String test(String code){
       String user="1";
        userService.save("UserDao.save");
        Map User1=userService.findByUsername("lile");
        System.out.println(User1);
       return  User1.toString();
    }
}